package com.note.common.domain;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDateTime;

/**
 * 笔记实体类
 * 对应数据库note表，存储用户的笔记内容
 */
@EqualsAndHashCode(callSuper = true)
@Data
@ToString
@AllArgsConstructor
@NoArgsConstructor
@Entity(name = "note")
@TableName("note")
@Schema(description = "笔记实体")
public class Note extends BaseEntity {

    /**
     * 笔记ID
     */
    @Id
    @TableId(value = "id", type = IdType.AUTO)
    @Schema(description = "笔记ID", example = "1")
    private Long id;

    /**
     * 所属集合ID
     */
    @TableField("collection_id")
    @Schema(description = "所属集合ID", example = "1")
    private Long collectionId;

    /**
     * 创建用户ID
     */
    @TableField("user_id")
    @Schema(description = "创建用户ID", example = "1")
    private Long userId;

    @TableField
    @Schema(description = "删除标记 0:正常 1:删除", example = "0")
    private Integer deleted = 0;

    /**
     * 笔记标题
     */
    @TableField("title")
    @Schema(description = "笔记标题", example = "Spring Boot学习笔记")
    private String title;

    /**
     * 笔记内容ID (MongoDB中的_id)
     */
    @TableField("content_id")
    @Schema(description = "笔记内容ID", example = "60a6c59c8f7d587a10b0c1a2")
    private String contentId;

    /**
     * 图片地址
     */
    @TableField("icon")
    @Schema(description = "图片地址", example = "https://example.com/image.jpg")
    private String icon;

    /**
     * 表情符号
     */
    @TableField("emoji")
    @Schema(description = "表情符号", example = "📝")
    private String emoji;

    /**
     * 版本号
     */
    @TableField("version")
    @Schema(description = "版本号", example = "1")
    private Integer version;

    /**
     * 是否公开 0-私有 1-公开
     */
    @TableField("is_public")
    @Schema(description = "是否公开 0-私有 1-公开", example = "0")
    private Integer isPublic;

    /**
     * 阅读次数
     */
    @TableField("view_count")
    @Schema(description = "阅读次数", example = "0")
    private Integer viewCount;

    @Column(name = "created_at")

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") // 修正月份MM和小时HH的大小写
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") // 修正时区写法
    @TableField(value = "created_at", fill = FieldFill.INSERT)
    @Schema(description = "创建时间", example = "2023-10-01T12:00:00")
    private LocalDateTime createdAt;

    @Column(name = "updated_at")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") // 修正月份MM和小时HH的大小写
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") // 修正时区写法
    @TableField(value = "updated_at", fill = FieldFill.INSERT_UPDATE)
    @Schema(description = "更新时间", example = "2023-10-01T12:00:00")
    private LocalDateTime updatedAt;
}